package com.like.receivers;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.like.entity.EventWrapper;
import com.like.entity.PushAmount;
import com.like.likeutils.network.GsonUtil;

import org.greenrobot.eventbus.EventBus;

import cn.jpush.android.api.JPushInterface;

public class PushMessageReceiver extends BroadcastReceiver {

    public static final String TAG_PUSH = "push_msg";

    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle bundle = intent.getExtras();
        if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
        } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
            String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
            String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
            System.out.println("message------------------>" + message);
            System.out.println("extras------------------->" + extras);
            String data = extras;
            try {
                PushAmount amount = GsonUtil.gson.fromJson(data, PushAmount.class);
                EventBus.getDefault().postSticky(new EventWrapper(amount, TAG_PUSH));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }
}
